#include "StdAfx.h"
#include "Platform.h"
#include "Helper.h"
#include "Time.h"

using namespace std;

Platform::Platform(IDirect3DDevice9 *pd3dDevice)
	:m_pd3dDevice(pd3dDevice),
	m_fWidth(10.0f),
	m_fHeight(0.5f),
	m_fDepth(5.0f),
	m_fRadius(20.0f),
	m_fAngle(0.0f),
	m_vecPosition(0.0f, 0.0f, 0.0f),
	m_vecLook(0.0f, 0.0f, 1.0f)
{
	D3DXCreateBox(m_pd3dDevice, m_fWidth, m_fHeight, m_fDepth, &m_pCube, 0);
	DrawMeshColor(m_pd3dDevice, &m_pCube, 1.0f, 0.0f, 1.0f, 1.0f);
}

Platform::~Platform(void)
{
	SAFE_RELEASE(m_pCube);
}

void Platform::SetOrbitRadius(float fRadius)
{
	m_fRadius = fRadius;
}

float Platform::Width() const
{
	return m_fWidth;
}

float Platform::Height() const
{
	return m_fHeight;
}

float Platform::Depth() const
{
	return m_fDepth;
}

const D3DXVECTOR3 &Platform::Position() const
{
	return m_vecPosition;
}

const D3DXVECTOR3 &Platform::Look() const
{
	return m_vecLook;
}

const D3DXMATRIX &Platform::World() const
{
	return m_matWorld;
}

void Platform::UpdateRotationY(float fAngle)
{
	m_fRotationAngleY = fAngle;
}

void Platform::Update()
{
	m_fAngle += (float)Time::Delta() * 20.0f;

	float m_fRadian = D3DXToRadian(m_fAngle);

	D3DXMatrixTranslation(&m_matWorld, sin(m_fRadian) * m_fRadius, 0, cos(m_fRadian) * m_fRadius);
	D3DXVec3TransformCoord(&m_vecPosition, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &m_matWorld);

	D3DXVECTOR3 vecDistance = m_vecPosition - D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	cout << "Runtime Orbit Radius: " << D3DXVec3Length(&vecDistance) << endl;

	m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_matWorld);
	m_pCube->DrawSubset(0);
}
